package com.example.demo.controller;

import com.example.demo.model.User;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Auther: 宇宙第一帅
 * @Date: 2019/3/26 17:43
 * @Description:
 */
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    private UserService userService;

    @GetMapping("insert")
    public String insertt(String username, String password){
        Integer a = userService.insert(username,password);
            if(a == 1){
                return "成功";
            }else{
                return "失败";
            }
    }
    @GetMapping("delete")
    public  String delete(String id){
        Integer b = userService.delete(id);
        if(b == 1){
            return "成功";
        }else{
            return "失败";
        }
    }
    @GetMapping("update")
    public String update(User user){
        Integer c = userService.update(user);
        if(c== 1){
            return "成功";
        }else{
            return "失败";
        }
    }
    @GetMapping("select")
    public List<User> select(){
        return userService.select();
    }
    @GetMapping("idselect")
    public User idselect(String id){
        return userService.idselect(id);

    }
    @GetMapping("nameselect")
    public List<User> nameselect(String username){
        return userService.nameselect(username);
    }
    @GetMapping("login")
    public Integer login(String username, String password){
        return  userService.login(username,password);

    }
}
